package com.kikt.animationdemo;

import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;

import com.kikt.animationdemo.fragment.PhotoFragment;

/**
 * Created by kikt on 2016/1/16.
 */
public class PhotoActivity extends FragmentActivity {

    protected FragmentManager fm;
    protected PhotoFragment fragment;
    protected View mRootView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mRootView = View.inflate(this, R.layout.activity_photo, null);
        setContentView(mRootView);
        fm = getSupportFragmentManager();
        addFragment(new PhotoFragment(), "init");
    }

    public void addFragment(Fragment fragment, String tag) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(mRootView.getId(),fragment, tag);
        ft.commit();
    }

    public void replaceFragment(final Fragment fragment, final Rect outRect, final Drawable drawable) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.remove(this.fragment);
        ft.replace(mRootView.getId(), fragment, "f1");
        ft.commit();
    }

    public void replaceFragment(final Fragment fragment, String tag) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(mRootView.getId(), fragment, tag);
        ft.commit();
    }
}
